package com.ruoyi.safe.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.safe.domain.TAppUser;
import com.ruoyi.safe.service.ITAppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户端用户信息Controller
 *
 * @author ruoyi
 * @date 2025-03-22
 */
@RestController
@RequestMapping("/safe/clientUser")
public class TAppUserController extends BaseController {
    @Autowired
    private ITAppUserService tAppUserService;

    /**
     * 查询客户端用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('safe:appUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAppUser tAppUser) {
        startPage();
        List<TAppUser> list = tAppUserService.selectTAppUserList(tAppUser);
        return getDataTable(list);
    }

    /**
     * 导出客户端用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('safe:appUser:export')")
    @Log(title = "客户端用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAppUser tAppUser) {
        List<TAppUser> list = tAppUserService.selectTAppUserList(tAppUser);
        ExcelUtil<TAppUser> util = new ExcelUtil<TAppUser>(TAppUser.class);
        util.exportExcel(response, list, "客户端用户信息数据");
    }

    /**
     * 获取客户端用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('safe:appUser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(tAppUserService.selectTAppUserByUserId(userId));
    }

    /**
     * 新增客户端用户信息
     */
    @PreAuthorize("@ss.hasPermi('safe:appUser:add')")
    @Log(title = "客户端用户信息", businessType = BusinessType.INSERT, logType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAppUser tAppUser) {
        return toAjax(tAppUserService.insertTAppUser(tAppUser));
    }

    /**
     * 修改客户端用户信息
     */
    @PreAuthorize("@ss.hasPermi('safe:appUser:edit')")
    @Log(title = "客户端用户信息", businessType = BusinessType.UPDATE, logType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAppUser tAppUser) {
        return toAjax(tAppUserService.updateTAppUser(tAppUser));
    }

    /**
     * 删除客户端用户信息
     */
    @PreAuthorize("@ss.hasPermi('safe:appUser:remove')")
    @Log(title = "客户端用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(tAppUserService.deleteTAppUserByUserIds(userIds));
    }
}
